/***************************************************************************
//* Foxit Software Inc.
//* Copyright(C) 2005-2012, all rights reserved.
//*
//* The following code is copyrighted and contains proprietary information
//* and trade secrets of Foxit Software Inc.                                                      *
***************************************************************************/

/**
* 配置管理;
*/

define(function (require, exports, module) {   
    
    var ReaderEngineType = WebPDF.ReaderEngineType = {
        // Reader base on image.
        IMAGE: 0,
        // Reader base on HTML5.
        HTML5: 1
    };
    
    /**
     * @namespace
     * @memberOf WebPDF
	 * @description Configuration of the App.
     * @ignore
     */
    var Config = WebPDF.Config = function(options){       
        _.extend(this, _.extend(Config.defaults, options));
        
        if (!this.baseUrl) {
            this.baseUrl = "";
        } 
        else {
            if(this.baseUrl.lastIndexOf("/")!= this.baseUrl.length-1 
               && this.baseUrl.lastIndexOf("\\")!=this.baseUrl.length-1){
                this.baseUrl += "/";
            }
        }
        if (!this.url) {
            this.url = "";
        }          
        else {
            if(this.url.lastIndexOf("/")!=this.url.length-1 
               && this.url.lastIndexOf("\\")!=this.url.length-1){
                this.url += "/";
            }
        }
        //if (!options.language) {
            this.language = "en-US";
        //}
       
         
        if(!this.readerType){
            this.readerType = ReaderEngineType.IMAGE;
        }         
         
        if (WebPDF.Environment.mobile) {              
            this.defaultZoom = WebPDF.ZOOM_FIT_WIDTH;
        }    
    }   
    
     

    /**
     * default configuration
     * @namespace
     * @memberOf WebPDF.Config
     */
    WebPDF.Config.defaults =
    {
        /**
         * @description default language.
         * 'en-US' and 'zh-CN' are currently supported.
         * 'en-US' represents for english, and 'zh-CN' represents for chinese.
         * Default value is 'en-US'.
         * @type {String}
         */
        language: 'en-US',

        defaultLanguage: 'en-US',
        /**
         * An array of available zoom level list, default value is [0.5,0.75,1.0,1.25,1.5,2.0].
         */
        zoomList: [0.5,0.75,1.0,1.25,1.5,2.0],
        /**
         * 最小放大倍数;
         * @ignore
         */
        minZoomSize: 0.5,
        /**
         * 最大放大倍数;
         * @ignore
         */
        maxZoomSize: 2.0,
        /**
         * 渐进式加载页面，每次能加载的最大页数，为-1表示所有页面;
         * @ignore
         */
        maxNewPagesPerTime: 20,
        /**
         * 渐进式缩放页面，每次能缩放的最大页数，为-1表示所有页面;
         * @ignore
         */
        maxResizePagesPerTime: 20,
        requestRetryCount: 50,
        maxRequestRetryCount: 100,
        requestRetryInterval: 2000,
        maxManifestRetryCount: 60,
        errPageImgWidth:558,
        errPageImgHeight:106,
        /**
         * Default zoom level, default value is 1.0 .
         * @type {Number} | {String}
         */
        defaultZoom: 1.0,
        /**
         * @description The navigation panel will be display by default, if you hide the navigation panel on start, just set this value to false.
         * @type {Boolean}
         * @ignore
         */
        leftPanelShowOnStart: true,
        /**
         * @description The download button in the toolbar will be display by default if the document can’t be downloaded by user, 
 		 * if you want to hide the download button, just set this value to false.
         * @type {Boolean}
         * @ignore
         */
        showDownloadLimitBtn: true,
        /**
         * @description Following styles will be added to the viewer to disable printing when the end user does not have permission to print the PDF document.
         * If you do not want add these styles, just set this value to false.
         *  <p>
 		 *	<style media="print">
 		 *	body{ display:none; } 
 		 *	</style>
 		 *  </p>
         * @type {Boolean} 
         */
        disablePrint: true,
        TooltipTimeout: 3000,
        autoDetectElasticScroll: true,
        /**
         * Type of scroll bar. default value is WebPDF.PDFView.ScrollBarType.CUSTOM_SCROLL_BAR.
         * @type {WebPDF.PDFView.ScrollBarType}
         */
        scrollBarType : 0,
        /**
         * Root url of data request.
         * @ignore
         */
        url : "./",
        /**
         * Name of current document, default value is "".
         */
        fileName: "",
        /**
         * Whether use form mode to render PDFs. default value is false.
         */
        formMode: false,

        /**
         * Default title of dialog.
         */
        defaultDialogTitle: null,
        /**
         * 是否跨域标识，默认为true，为第三方网站引用使用，当前网站的页面需设为false
         * @ignore
         */
        crossDomain: true
    };

    /**
     * @name WebPDF.Config.ToolBar
 	 * @namespace
     * @ignore
     * @description Configration of Toolbar. default configration is.
 	*<pre>	
 	*	WebPDF.Config.ToolBar =
 	*	[
 	*			{
 	*				'name': 'Logo', 'btns': ['FoxitLog'],'width':250
 	*			},
 	* 			{
 	*				'name': 'Tools', 'btns': ['HandTool', 'TextTool', 'ToolBarSeparator']
 	*			},
 	*			{
 	*				'name': 'document', 'btns': ['ToolBarSeparator', 'First Page', 'Prev Page', 'Next Page', 'Last Page', 'GotoPage', 'ToolBarSeparator']
 	*			},
 	*			{
 	*				'name': 'Zoom', 'btns': ["FitWidth","ZoomIn", "ZoomOut", "SelectZoom", 'ToolBarSeparator']
 	*			},
 	*			{
 	*				'name': 'Search', 'btns': ['SearchText', 'SearchPrev', 'SearchNext', 'ToolBarSeparator']
 	*			},
 	*			{
 	*				'name': 'DownloadPDF', 'btns': ['DownLoadPDF', 'ToolBarSeparator']
 	*			},
 	*			{
 	*				'name': 'Highlight', 'btns': ['Highlight', 'ExportData', 'ToolBarSeparator']
 	*			},
 	*			{
 	*				'name': 'DocProperties', 'btns': ['PopupDocProperties', 'ToolBarSeparator']
 	*			},
 	*	];
 	*  </pre>
    */
    WebPDF.Config.ToolBar =
    [
            {
                'name': 'Logo', 'btns': ['FoxitLog'],'width':250
            },
            {
                'name': 'Tools', 'btns': ['ToolBarSeparator', 'HandTool', 'TextTool']
            },
            {
                'name': 'document', 'btns': ['ToolBarSeparator', 'First Page', 'Prev Page', 'Next Page', 'Last Page', 'GotoPage', 'ToolBarSeparator']
            },
            {
                'name': 'Zoom', 'btns': ["FitWidth","ZoomIn", "ZoomOut", "SelectZoom", 'ToolBarSeparator']
            },
            {
                'name': 'Search', 'btns': ['SearchText', 'SearchPrev', 'SearchNext', 'ToolBarSeparator']
            },
            {
                'name': 'DownloadPDF', 'btns': ['DownLoadPDF', 'ToolBarSeparator']
            },
            {
                'name': 'Highlight', 'btns': ['Highlight', 'ExportData', 'ToolBarSeparator']
            },
            {
                'name': 'DocProperties', 'btns': ['PopupDocProperties', 'ToolBarSeparator']
            }
            ,
            {
                'name': 'CommentAnnotTool', 'btns': ['ToolBarSeparator', 'HighlightAnnot', 'UnderlineAnnot']
            }
    ];
    
    WebPDF.Config.RibbonToolBar =
    {
    	'left': ['DownLoadPDF','ToolBarSeparator','HandTool','TextTool'],
    	'right' : ['SearchText','SearchPrev','SearchNext','QRCode']
    	/*'right' : ['SearchText','QRCode']*/
    };

    WebPDF.Config.RibbonStatusBar =
    {
    	'center' : ['First Page', 'Prev Page','GotoPage', 'Next Page', 'Last Page'],
    	'right' : ["FitWidth","SelectZoom", "ZoomOut","ZoomSlider","ZoomIn" ]
    };
    
    /**
 	 * @namespace
     * @memberOf  WebPDF.Config
     * @description Default configuration of context menu. Change this configuration if you want to customize context menu.
 	 *<pre>
     *  WebPDF.Config.MenuBar =
 	 *  [
     *      {
	 *           'plugin': 'document',
	 *            'items':[
	 *                { 'item': 'MenuZoom50', 'subitems': [] },
	 *                { 'item': 'MenuZoom75', 'subitems': [] },
	 *                { 'item': 'MenuZoom100', 'subitems': [] },
	 *                { 'item': 'MenuZoom125', 'subitems': [] },
	 *                { 'item': 'MenuZoom150', 'subitems': [] },
	 *                { 'item': 'MenuZoom200', 'subitems': [] },
	 *                { 'item': 'FitWidth', 'subitems': [] },
	 *                { 'item': 'MenuSeparator', 'subitems': [] },
	 *                { 'item': 'MenuPrevPage', 'subitems': [] },
	 *                { 'item': 'MenuNextPage', 'subitems': [] }
	 *            ]
	 *        },
	 *        {
	 *            'plugin': 'DocProperties',
	 *             'items':[
	 *                { 'item': 'MenuSeparator', 'subitems': [] },
	 *                { 'item': 'MenuDocProperties', 'subitems': [] }
	 *            ]
	 *        }
 	 *  ];
 	 * </pre>
     */
    WebPDF.Config.MenuBar =
    {
        'document' : {            
             'items':[
                 { item: 'MenuReadMode',    subitems: [] },
                 { item: 'MenuFullScreen',  subitems: [] },
                 { item: 'MenuSeparator',   subitems: [] },
                 { item: 'MenuZoomIn',      subitems: [] },
                 { item: 'MenuZoomOut',     subitems: [] },
                 { item: 'MenuSeparator',   subitems: [] },
                 { item: 'MenuActualSize',  subitems: [] },
                 { item: 'MenuFitPage',     subitems: [] },
                 { item: 'MenuFitWidth',    subitems: [] },
                 { item: 'MenuFitVisible',  subitems: [] },
                 { item: 'MenuSeparator',   subitems: [] },
                 { item: 'MenuRotateLeft',  subitems: [] },
                 { item: 'MenuRotateRight',  subitems: [] },
                 { item: 'MenuSeparator',    subitems: [] },
                 { item: 'MenuGetALink',    subitems: [] }
             ]
         },
         'annot':{           
             'items':[
                 { item: 'MenuAnnotCut',    subitems: [] },
                 { item: 'MenuAnnotCopy',  subitems: [] },
                 { item: 'MenuAnnotPaste',   subitems: [] },
                 { item: 'MenuSeparator',   subitems: [] },
                 { item: 'MenuAnnotDelete',      subitems: [] },
                 { item: 'MenuSeparator',   subitems: [] },
                 { item: 'MenuAnnotOpenPopupNote',     subitems: [] },
                 { item: 'MenuAnnoOpenAllPopups',   subitems: [] },
                 { item: 'MenuAnnotCloseAllPopups',  subitems: [] }           
             ]
         },
         'DocProperties': {            
              'items':[
                 { item: 'MenuSeparator', subitems: [] },
                 { item: 'MenuDocProperties', subitems: [] }
             ]
         }
       };
    
    
    WebPDF.Config.TextSelectionOperationBar =
        [
            { 'item': 'MenuTextCopy', 'subitems': [] },
            { 'item': 'MenuSeparator',   subitems: [] },
            { 'item': 'MenuHighlight', 'subitems': [] },
            { 'item': 'MenuStrikeout', 'subitems': [] },
            { 'item': 'MenuUnderline', 'subitems': [] },
        ];


    /**
     * @name WebPDF.Config.Plugins
 	* @namespace
     * @private
     * @description Configration of Plugins. default configuration is.
 	*<pre>	
 	*	 WebPDF.Config.Plugins =
 	*	 {
 	*		load:{
 	*			Annot: true,
 	*			FindTool: true,
 	*			NavigationPanel: true,
 	*			Thumbnail: true,
 	*			Bookmark: true,
 	*			DocProperties: true,
 	*			ToolBar: true,
 	*			Menu: true,
 	*			Form: true,
 	*			TextSelection: true,
 	*			Signature: true,
    *			Edit: true
 	*		},
 	*		flag:{
 	*			Annot: 0x0001,
 	*			FindTool: 0x0002,
 	*			NavigationPanel: 0x0004,
 	*			Thumbnail: 0x0008,
 	*			Bookmark: 0x0010,
 	*			DocProperties: 0x0020,
 	*			ToolBar: 0x0040,
 	*			Menu: 0x0080,
 	*			Form: 0x0100,
 	*			TextSelection: 0x0200,
 	*			Signature: 0x0400,
 	*			Edit: 0x0800
 	*		}
 	*	 };
 	*  </pre>
     */
    WebPDF.Config.Plugins =
    {
        load:{
            Annot: true,
            FindTool: true,
            NavigationPanel: true,
            Thumbnail: true,
            Bookmark: true,
            DocProperties: true,
            ToolBar: true,
            Menu: true,
            Form: true,
            TextSelection: true,
            Signature: true,
            Edit: true
        },
        flag:{
            Annot: 0x0001,
            FindTool: 0x0002,
            NavigationPanel: 0x0004,
            Thumbnail: 0x0008,
            Bookmark: 0x0010,
            DocProperties: 0x0020,
            ToolBar: 0x0040,
            Menu: 0x0080,
            Form: 0x0100,
            TextSelection: 0x0200,
            Signature: 0x0400,
            Edit: 0x0800
        }
    };

    module.exports = Config;
});